package com.company.笔试.和为s的两个数字;

import java.util.ArrayList;
public class Solution {
    public ArrayList<Integer> FindNumbersWithSum(int [] array,int sum) {
        ArrayList<Integer> res = new ArrayList();
        if(array==null){
            return res;
        }
        int left =0;
        int right = array.length-1;
        while(left<right){
            if(array[left]+array[right]==sum){
                res.add(array[left]);
                res.add(array[right]);
                break;
            }else if(array[left]+array[right]>sum){
                right--;
            }else{
                left++;
            }
        }
        
        return res;
    }
}